import { Engine } from '../engine.js';
import { DateUtil } from '../../utils/dateUtil.js'; // 假设你有日期格式化方法

export class EmployeeFilter {
    constructor(storeId = null,name = null) {
        this.name = name;
        this.joinStartDate = null;
        this.joinEndDate = null;
        this.enable = null;
        this.authorized = null;
        this.storeId = storeId || Engine.profile?.filterStore?.id || null;
    }

    clear() {
        this.name = null;
        this.joinStartDate = null;
        this.joinEndDate = null;
        this.enable = null;
        this.authorized = null;
    }

    clone() {
        const copy = new EmployeeFilter(this.storeId);
        copy.name = this.name;
        copy.joinStartDate = this.joinStartDate;
        copy.joinEndDate = this.joinEndDate;
        copy.enable = this.enable;
        copy.authorized = this.authorized;
        return copy;
    }

    toJson() {
        const ret = {};

        if (this.name) ret['a_lke_nickName'] = this.name;
        if (this.enable != null) ret['b_status'] = this.enable ? 1 : 0;
        if (this.authorized != null) ret['b_whetherCanLogin'] = this.authorized ? 1 : 0;

        if (this.joinStartDate && this.joinEndDate && this.joinEndDate > this.joinStartDate) {
            ret['a_gte_workTime'] = DateUtil.formatDate(this.joinStartDate, "yyyy-MM-dd HH:mm:ss");
            ret['a_lte_workTime'] = DateUtil.formatDate(this.joinEndDate, "yyyy-MM-dd HH:mm:ss");
        } else if (this.joinStartDate) {
            ret['a_gte_workTime'] = DateUtil.formatDate(this.joinStartDate, "yyyy-MM-dd HH:mm:ss");
        } else if (this.joinEndDate) {
            ret['a_lte_workTime'] = DateUtil.formatDate(this.joinEndDate, "yyyy-MM-dd HH:mm:ss");
        }

        if (this.storeId) ret['ign_storeId'] = this.storeId;

        return ret;
    }
}
